package com.poetize.plus.entity.dto;

import com.poetize.plus.entity.po.Friend;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Null;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Update;

/**
 * @author zuosy
 * @created 2024/5/14 17:24
 */
public record FriendDTO(
        @Schema(description = "ID")
        @Null(message = "ID必须为空", groups = {Insert.class})
        @NotNull(message = "ID不能为空", groups = {Update.class})
        Long id,

        @Schema(description = "网站名称")
        @NotNull(message = "网站名称不能为空", groups = {Insert.class, Update.class})
        String name,

        @Schema(description = "网站域名")
        @NotNull(message = "网站域名不能为空", groups = {Insert.class, Update.class})
        String url,

        @Schema(description = "网站封面")
        @NotNull(message = "网站封面不能为空", groups = {Insert.class})
        String cover,

        @Schema(description = "网站简介")
        @NotNull(message = "网站简介不能为空", groups = {Insert.class, Update.class})
        String introduction,

        @Schema(description = "友链类型 0:更好；1:普通")
        @NotNull(message = "友链类型不能为空", groups = {Update.class})
        String type,

        @Schema(description = "审核状态")
        @NotNull(message = "审核状态不能为空")
        Boolean status
) {

    /**
     * DTO转实体类
     *
     * @param friendDTO
     * @return
     */
    public static Friend convertDTO(FriendDTO friendDTO) {
        return new Friend(friendDTO.id, friendDTO.name, friendDTO.url, friendDTO.cover, friendDTO.introduction, friendDTO.type, friendDTO.status);
    }
}
